package com.jingdianjichi.club.gateway.entity;
import com.jingdianjichi.club.gateway.enums.ResultEnumCode;
import lombok.Data;

@Data
public class Result<T> {
    private int code;
    private String msg;
    private Boolean success;
    private T data;

    public static Result ok(){
        Result result = new Result();
        result.setSuccess(true);
        result.setCode(ResultEnumCode.SUCCESS.getCode());
        result.setMsg(ResultEnumCode.SUCCESS.getDesc());
        return result;
    }

    public static <T> Result ok(T data){
        Result result = new Result();
        result.setSuccess(true);
        result.setCode(ResultEnumCode.SUCCESS.getCode());
        result.setMsg(ResultEnumCode.SUCCESS.getDesc());
        result.setData(data);
        return result;
    }
    public static Result fail(){
        Result result = new Result();
        result.setSuccess(false);
        result.setCode(ResultEnumCode.FAIL.getCode());
        result.setMsg(ResultEnumCode.FAIL.getDesc());
        return result;
    }

    public static <T> Result fail(T data){
        Result result = new Result();
        result.setSuccess(false);
        result.setCode(ResultEnumCode.FAIL.getCode());
        result.setMsg(ResultEnumCode.FAIL.getDesc());
        result.setData(data);
        return result;
    }
    public static Result fail(Integer code,String message){
        Result result = new Result();
        result.setSuccess(false);
        result.setCode(code);
        result.setMsg(message);
        result.setData(message);
        return result;
    }
}
